package com.itstudy.controller;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.support.jaxrs.FastJsonFeature;
import com.itstudy.pojo.Result;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.*;

@RestController
@RequestMapping("markDown")
public class MarkDownController {
    @RequestMapping("read")
    public Result read(){
        try {
            File file = new File("C:/Users/杨鸿靖/Desktop/day09-字节缓冲流&字符流.md");
            BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file),"UTF-8"));
            String line;
            StringBuilder stringBuilder = new StringBuilder("[TOC]");
            while((line = reader.readLine())!=null){
                stringBuilder.append(line);
                stringBuilder.append("\n");
            }
            reader.close();

            return new Result(true,"读取文件成功",stringBuilder.toString());
        } catch (IOException e) {
            e.printStackTrace();
            return new Result(false,"读取文件失败");
        }

    }
}
